<%@ include file="/WEB-INF/pages/common/taglibs.jsp" %>
<script type="text/javascript">
    function uploadFeedbackAttach(){
        var currentForm = document.forms["uploadForm"];
        if(trim(currentForm.elements["attach.upload"].value)==""){
             alert('<s:text name="label.upload.empty"/>')
         }else{
            submitForm("uploadForm", "uploadFeedbackAttach.action");    
        }

    }

    function back(){
        submitForm("uploadForm","clientSummary.action");
    }

    function fclick(obj, objButton) {
       with (obj) {
           scrollTop = event.y - offsetHeight / 2
           style.posLeft = event.x - offsetWidth / 2
       }
   }


    function downloadFeedBackAttach(attachId){
        var currentForm = document.forms["uploadForm"];
        currentForm.elements["downloadAttachId"].value = attachId;
        submitForm("uploadForm", "downloadFeedBackAttach.action");
    }

    function deleteFeedBackAttach(){
         if (!atLeastOneRecordChecked('uploadFormDiv')) {
            alert('<s:text name="label.select.atleast.one.record"/>');
        } else {
            if (window.confirm('<s:text name="label.confirm.delete"/>')) {
                var rs="";
                o = document.getElementById('uploadFormDiv');
                var resultList = o.getElementsByTagName("input");
                for (var i = 0; i < resultList.length; i++) {
                    if (resultList[i].type == 'checkbox') {
                        if (resultList[i].checked) {
                            if(rs==""){
                                rs=resultList[i].value;
                            }else{
                                rs=rs+"|"+resultList[i].value;
                            }
                        }
                    }
                }
                var currentForm = document.forms["uploadForm"];
                currentForm.elements["deleteFeedBackAttachId"].value = rs;
                submitForm("uploadForm", "deleteFeedBackAttach.action");
            }
        }
    }


</script>
<s:form name="uploadForm" action="" enctype="multipart/form-data">
    <s:hidden name="downloadAttachId"/>
    <s:hidden name="deleteFeedBackAttachId"/>
    <table class="sectionBorder" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td align="left" valign="bottom" class="main_page_content_icon" width="4%">
                <img src='<c:url value="/images/body-icon_check.gif"/>'  width="29" height="44">
            </td>
            <td valign="bottom" class="page_title_bg" width="96%" colspan="2">
                <span class="page_title">
                     <s:if test='#attr.user.userRole=="A"'>
                        <s:text name='label.feedback.download'/>
                     </s:if>
                     <s:if test='#attr.user.userRole!="A"'>
                         <s:text name='label.feedback.upload'/>
                     </s:if>
                </span>
            </td>
        </tr>
    </table>
    <s:if test='#attr.user.userRole!="A"'>
        <table class="sectionBorder" width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr class="odd">
                <td class="form_label_padded" width="10%" nowrap><s:text name="label.feedback.content"/></td>
                <td class="form_label_padded" width="2%">:</td>
                <td class="txtData" align="left">
                       <input id="f_file2" readonly="true">&nbsp;<input type="button" onmouseover="fclick(t_file2,this)"
                                                                    value="<s:text name='label.browse'/>" class="button">
                        <s:file name="attach.upload" contentEditable="false" style="position:absolute;filter:alpha(opacity=0);width:30px;" id="t_file2"
                                           onchange="f_file2.value=this.value" />
                </td>
            </tr>
        </table>
    </s:if>
<div id='uploadFormDiv'>
    <table border="0" align="center" cellpadding="0" cellspacing="0" class="body_content dataTable full_width bordered">
        <tr>
            <th width="3%"><s:text name='label.seq'/></th>
             <s:if test='#attr.user.userRole=="A"'>
                <th width="3%"/>
             </s:if>
            <th width="17%"><s:text name='label.client.light.deptId'/></th>
            <th width="17%"><s:text name='label.create.date'/></th>            
            <th width="80%"><s:text name='label.upload'/></th>
        </tr>
        <s:iterator id="uList" value="%{uploadList}" status="status">
            <tr>                                               
                <td>
                     <s:property value="#status.count"/>
                </td>
                <s:if test='#attr.user.userRole=="A"'>
                    <td>
                        <s:checkbox name="uList[%{#status.count-1}].selectId" fieldValue="%{#uList.attachId}"/>    
                    </td>

                </s:if>
                <td>
                     <s:property value="#uList.deptDesc"/>
                </td>
                <td>
                     <s:property value="#uList.createDt"/>
                </td>
                <td>
                    <a href='javascript:downloadFeedBackAttach(<s:property value="#uList.attachId"/>)'>
                        <s:property value="#uList.uploadFileName"/>
                     </a>
                </td>
            </tr>
        </s:iterator>
    </table>
</div>    
    <table class="sectionBorder" width="100%">
        <tr>
            <td class="txtData" align="left" width="100%">
                <s:if test='#attr.user.userRole!="A"'>
                <input type="button" class="button" value="<s:text name='label.save'/>" onclick="uploadFeedbackAttach();">
                </s:if>
                <s:if test='#attr.user.userRole=="A"'>
                    <input type="button" class="button" value="<s:text name='label.delete'/>" onclick="deleteFeedBackAttach();">
                </s:if>
                <input type="button" class="button" value="<s:text name='label.back'/>" onclick="back();">

            </td>
        </tr>
    </table>
</s:form>